package com.kinsin.kinsinlogsystem;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

public class LogServiceConfig implements Serializable {
    private String basePath; // 存储路径
    private String zipPath; // 压缩路径
    private int maxTotalSize; // 存储总大小，所有文件占用的总大小
    private int storageReleaseStandard; // 存储空间释放标准容量（每次检测到容量满了，则释放到这个数值就可以停止了。 比如发现容量超过530了，那么则进行文件删除，每删一个都检测一下容量，直到容量处于450以内了，就停止删除）
    private int tempFileMaxSize; // 临时文件最大大小
    private boolean normalWriteMode; // 临时文件写入模式， true为普通模式，false为文件映射模式
    private int storageCheckInterval; // 存储释放间隔时间
    private TimeUnit storageCheckTimeUnit; // 存储释放间隔时间单位

    // Builder模式实现
    public static class Builder {
        private String basePath = "";
        private String zipPath = "";
        private int maxTotalSize = 530 * 1024 * 1024;
        private int storageReleaseStandard = 450 * 1024 * 1024;
        private int tempFileMaxSize = 10 * 1024 * 1024;
        private boolean normalWriteMode = false;
        private int storageCheckInterval = 10;
        private TimeUnit storageCheckTimeUnit = TimeUnit.MINUTES;

        public Builder setBasePath(String path) {
            this.basePath = path.endsWith("/") ? path : path + "/";
            return this;
        }

        public Builder setZipPath(String path) {
            this.zipPath = path.endsWith("/") ? path : path + "/";
            return this;
        }

        public Builder setMaxTotalSize(int size) {
            this.maxTotalSize = size;
            return this;
        }

        public Builder setStorageReleaseStandard(int size) {
            this.storageReleaseStandard = size;
            return this;
        }

        public Builder setTempFileMaxSize(int size) {
            this.tempFileMaxSize = size;
            return this;
        }

        public Builder setNormalWriteMode(boolean mode) {
            this.normalWriteMode = mode;
            return this;
        }

        public Builder setStorageCheckInterval(int interval) {
            this.storageCheckInterval = interval;
            return this;
        }

        public Builder setStorageCheckTimeUnit(TimeUnit unit) {
            this.storageCheckTimeUnit = unit;
            return this;
        }

        public LogServiceConfig build() {
            return new LogServiceConfig(this);
        }
    }

    private LogServiceConfig(Builder builder) {
        this.basePath = builder.basePath;
        this.zipPath = builder.zipPath;
        this.maxTotalSize = builder.maxTotalSize;
        this.storageReleaseStandard = builder.storageReleaseStandard;
        this.tempFileMaxSize = builder.tempFileMaxSize;
        this.normalWriteMode = builder.normalWriteMode;
        this.storageCheckInterval = builder.storageCheckInterval;
        this.storageCheckTimeUnit = builder.storageCheckTimeUnit;
    }

    public String getBasePath() {
        return basePath;
    }

    public String getZipPath() {
        return zipPath;
    }

    public int getMaxTotalSize() {
        return maxTotalSize;
    }

    public int getStorageReleaseStandard() {
        return storageReleaseStandard;
    }

    public int getTempFileMaxSize() {
        return tempFileMaxSize;
    }

    public boolean isNormalWriteMode() {
        return normalWriteMode;
    }

    public int getStorageCheckInterval() {
        return storageCheckInterval;
    }

    public TimeUnit getStorageCheckTimeUnit() {
        return storageCheckTimeUnit;
    }
}